package com.usian.wemedia.controller;

import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.usian.apis.wemedia.WmUserControllerApi;
import com.usian.model.common.dtos.ResponseResult;
import com.usian.model.common.enums.AppHttpCodeEnum;
import com.usian.model.media.pojos.WmUser;
import com.usian.wemedia.service.impl.WmUserServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/api/v1/user")
public class WmUserController implements WmUserControllerApi {

    @Autowired
    private WmUserServiceImpl service;

    @PostMapping("/save")
    @Override
    public ResponseResult save(@RequestBody WmUser wmUser) {
        //为空返回
        if(wmUser==null ) return ResponseResult.errorResult(AppHttpCodeEnum.PARAM_INVALID);
        //添加到数据库
        service.save(wmUser);
        //返回成功信息
        return ResponseResult.okResult(wmUser);
    }
    @GetMapping("/findByName/{name}")
    @Override
    public WmUser findByname(@PathVariable String name) {
        //通过lambda表达式过滤根据名称查询信息
        WmUser one = service.getOne(Wrappers.<WmUser>lambdaQuery().eq(WmUser::getName, name));
        return  service.getOne(Wrappers.<WmUser>lambdaQuery().eq(WmUser::getName,name));
    }
    @PostMapping("/updateAuthorid")
    @Override
    public ResponseResult updateAuthorid(@RequestBody WmUser wmUser) {
        service.updateById(wmUser);
        return service.success;
    }


}
